package ioliu;

import java.io.*;


//追加写入
public class Demo04 {
    public static void main(String[] args) {
        String s1="";
        BufferedReader br =null;
        BufferedWriter bw =null;
        try {

            File file = new File("E:\\stream\\a.txt");
            File file1 = new File("E:\\stream");
            if(!file1.exists()){
                file1.mkdirs();
            }
            String s;

            br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));

                                                             //FileOutputStream构造函数中的第二个参数true表示以追加形式写文件
            bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file1+"\\ f.txt" ,true)));
            while((s = br.readLine())!=null){

                //   System.getProperty("line.separator")相当于 加了一个换行符"\r\n"
                bw.write(s+System.getProperty("line.separator"));
                bw.flush();
            }
            bw.close();
            br.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
